<?php

namespace App\Models;


use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Eloquent\Model;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }

    public static function boot()
    {
        parent::boot();

        static::creating(function ($signIn) {
            $signIn->password = Hash::make( $signIn->password);;
        });

        static ::updating (function ($user){
            if ($user->password){
                $user->password = Hash::make( $user->password);;
            }
        });
    }

    public function  department()
    {
        return $this->hasOne (Department::class,"id","department_id");
    }
}
